﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Util.Domains;
using Util.Domains.Auditing;
using Util.Domains.Tenants;

namespace IterationLife.System.Models {
    /// <summary>
    /// 附件
    /// </summary>
    [Description( "附件" )]
    public partial class Attachment : AggregateRoot<Attachment>,ITenant,IDelete,IAudited {
        /// <summary>
        /// 初始化附件
        /// </summary>
        public Attachment() : this( Guid.Empty ) {
        }

        /// <summary>
        /// 初始化附件
        /// </summary>
        /// <param name="id">附件标识</param>
        public Attachment( Guid id ) : base( id ) {
        }

        /// <summary>
        /// 附件组编号
        /// </summary>
        public Guid? AttachmentGroupId { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        [Required(ErrorMessage = "名称不能为空")]
        [StringLength( 200, ErrorMessage = "名称输入过长，不能超过200位" )]
        public string Name { get; set; }
        /// <summary>
        /// 大小
        /// </summary>
        [Required(ErrorMessage = "大小不能为空")]
        public long Size { get; set; }
        /// <summary>
        /// 扩展名
        /// </summary>
        [Required(ErrorMessage = "扩展名不能为空")]
        [StringLength( 10, ErrorMessage = "扩展名输入过长，不能超过10位" )]
        public string Extensions { get; set; }
        /// <summary>
        /// 属性
        /// </summary>
        public string Attribute { get; set; }
        /// <summary>
        /// 地址
        /// </summary>
        [Required(ErrorMessage = "地址不能为空")]
        public string Address { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreationTime { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public Guid? CreatorId { get; set; }
        /// <summary>
        /// 最后修改时间
        /// </summary>
        public DateTime? LastModificationTime { get; set; }
        /// <summary>
        /// 最后修改人
        /// </summary>
        public Guid? LastModifierId { get; set; }
        /// <summary>
        /// 是否删除
        /// </summary>
        [Required(ErrorMessage = "是否删除不能为空")]
        public bool IsDeleted { get; set; }
        /// <summary>
        /// 租户
        /// </summary>
        [StringLength( 50, ErrorMessage = "租户输入过长，不能超过50位" )]
        public string TenantId { get; set; }
        
        /// <summary>
        /// 附件组
        /// </summary>
        public virtual AttachmentGroup AttachmentGroup { get; set; }
        
        /// <summary>
        /// 添加描述
        /// </summary>
        protected override void AddDescriptions() {
            AddDescription( "附件编号", Id );
            AddDescription( "附件组编号", AttachmentGroupId );
            AddDescription( "名称", Name );
            AddDescription( "大小", Size );
            AddDescription( "扩展名", Extensions );
            AddDescription( "属性", Attribute );
            AddDescription( "地址", Address );
            AddDescription( "创建时间", CreationTime );
            AddDescription( "创建人", CreatorId );
            AddDescription( "最后修改时间", LastModificationTime );
            AddDescription( "最后修改人", LastModifierId );
            AddDescription( "租户", TenantId );
        }
        
        /// <summary>
        /// 添加变更列表
        /// </summary>
        protected override void AddChanges( Attachment newEntity ) {
            AddChange( "Id", "附件编号", Id, newEntity.Id );            
            AddChange( "AttachmentGroupId", "附件组编号", AttachmentGroupId, newEntity.AttachmentGroupId );
            AddChange( "Name", "名称", Name, newEntity.Name );
            AddChange( "Size", "大小", Size, newEntity.Size );
            AddChange( "Extensions", "扩展名", Extensions, newEntity.Extensions );
            AddChange( "Attribute", "属性", Attribute, newEntity.Attribute );
            AddChange( "Address", "地址", Address, newEntity.Address );
            AddChange( "CreationTime", "创建时间", CreationTime, newEntity.CreationTime );
            AddChange( "CreatorId", "创建人", CreatorId, newEntity.CreatorId );
            AddChange( "LastModificationTime", "最后修改时间", LastModificationTime, newEntity.LastModificationTime );
            AddChange( "LastModifierId", "最后修改人", LastModifierId, newEntity.LastModifierId );
            AddChange( "TenantId", "租户", TenantId, newEntity.TenantId );
        }
    }
}